package scanner.impl;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import entity.Customer;
import scanner.DataScanner;
import util.DateHelper;

public class DataScannerImpl implements DataScanner {
	private InputStream in;
	private Scanner scaner;
	
	public DataScannerImpl(InputStream in) {
		super();
		this.in=in;
		scaner=new Scanner(in);
		
	}

	public List<Customer> scann() {
		List<String> list=preScan("regexpr");
		List<Customer> list1=new ArrayList<Customer>();
		String reg="\\s+";
		for(String s:list){
			String[] ss=s.split(reg);
			Customer c=new Customer();
			c.setId(Integer.parseInt(ss[0]));
			c.setName(ss[1]);
			c.setEmail(ss[2]);
			if(ss[3].equals("true")){
				c.setSex(true);
			}
			c.setBirth(DateHelper.parseToDate(ss[4]));
			list1.add(c);
		}
		
		return list1;
	}
	private List<String> preScan(String reg){
		List<String> list=new ArrayList<String>();
		while(scaner.hasNext()){
//			if(RegexHelper.isLegal(reg,scaner.nextLine())){
				list.add(scaner.nextLine());
//			}
		}
		return list;
	}
	
	
	

}
